/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manager.auxiliares;

import java.awt.Component;
import java.util.LinkedList;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Thiago
 */
public class ModuleMenu {

    LinkedList<String> subMenuList;
    String titleModule;
    JPanel jPanelMenu;
    JPanel jPanelSubMenu;
    LinkedList<JPanel> jPanelSubMenuItens;
    ImageIcon iconModule;
    Boolean selected;

    public ModuleMenu(LinkedList newSubMenuList, String newTitleModule, ImageIcon newIconModule) {
        subMenuList = newSubMenuList;
        titleModule = newTitleModule;
        iconModule = newIconModule;
        jPanelSubMenuItens = new LinkedList<JPanel>();
        selected = false;

        jPanelMenu = new JPanel();
        JLabel jLabelTitle = new JLabel();
        JLabel jLabelIconModule = new JLabel();
        JLabel jLabelIconSettings = new JLabel();
        jPanelMenu.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelMenu.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jPanelMenu.addMouseListener(new java.awt.event.MouseAdapter() {
            
            /**
             * Modificando a cor do menu com o evento de entrada do mouse
             */
            @Override
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                JPanel jPanel = ((JPanel) evt.getComponent());
                if (!selected) {//caso o botão não esteja selecionado
                    jPanel.setBackground(Configurations.getjPanelHoverColor());
                }
                Component[] components = jPanel.getComponents();
                Component component = null;
                for (int i = 0; i < components.length; i++) {
                    component = components[i];
                    if (component instanceof JLabel) {
                        component.setForeground(new java.awt.Color(255, 255, 255));
                    }
                }
            }

            @Override
            public void mouseExited(java.awt.event.MouseEvent evt) {
                JPanel jPanel = ((JPanel) evt.getComponent());
                if (selected) {//Menu esta selecionado
                    jPanel.setBackground(Configurations.getjPanelSelectedColor());
                } else {//Menu não esta selecionado
                    jPanel.setBackground(Configurations.getBackGroundColor());
                }
                Component[] components = jPanel.getComponents();
                Component component = null;
                for (int i = 0; i < components.length; i++) {
                    component = components[i];
                    if (component instanceof JLabel) {
                        component.setForeground(new java.awt.Color(0, 0, 0));
                    }
                }
            }
        });
        jPanelMenu.setLayout(null);

        jLabelTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelTitle.setText(titleModule);
        jLabelTitle.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jPanelMenu.add(jLabelTitle);
        jLabelTitle.setBounds(45, 5, 100, 20);

        jLabelIconModule.setIcon(iconModule); // NOI18N
        jPanelMenu.add(jLabelIconModule);
        jLabelIconModule.setBounds(2, 2, 35, 33);

        jPanelMenu.add(jLabelIconSettings);
        jLabelIconSettings.setBounds(164, 5, 20, 15);


        jPanelSubMenu = new JPanel();
        if (subMenuList.size() > 0) {
            jPanelSubMenu.setLayout(new java.awt.GridLayout(subMenuList.size(), 0));

            for (int i = 0; i < subMenuList.size(); i++) {
                JPanel subMenuItem = new JPanel();
                subMenuItem.setBackground(Configurations.getBackGroundColor());
                subMenuItem.setBorder(javax.swing.BorderFactory.createEtchedBorder());
                subMenuItem.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

                JLabel subMenuItemLabel = new JLabel();
                subMenuItemLabel.setText(subMenuList.get(i));
                subMenuItem.add(subMenuItemLabel, new java.awt.GridBagConstraints());
                subMenuItem.addMouseListener(new java.awt.event.MouseAdapter() {

                    @Override
                    public void mouseEntered(java.awt.event.MouseEvent evt) {
                        JPanel jPanel = ((JPanel) evt.getComponent());
                        Component[] components = jPanel.getComponents();
                        Component component = null;
                        for (int i = 0; i < components.length; i++) {
                            component = components[i];
                            if (component instanceof JLabel) {
                                component.setForeground(new java.awt.Color(175, 0, 0));
                            }
                        }
                    }

                    @Override
                    public void mouseExited(java.awt.event.MouseEvent evt) {
                        JPanel jPanel = ((JPanel) evt.getComponent());
                        Component[] components = jPanel.getComponents();
                        Component component = null;
                        for (int i = 0; i < components.length; i++) {
                            component = components[i];
                            if (component instanceof JLabel) {
                                component.setForeground(new java.awt.Color(0,0,0));
                            }
                        }
                    }
//                public void mouseReleased(java.awt.event.MouseEvent evt) {
//                    subMenuItemMouseReleased(evt);
//                }
                });
                subMenuItem.setLayout(new java.awt.GridBagLayout());

                jPanelSubMenuItens.add(subMenuItem);
                jPanelSubMenu.add(subMenuItem);
            }
        }
    }

    public JPanel getjPanelMenu() {
        return jPanelMenu;
    }

    public String getTitleModule() {
        return titleModule;
    }

    public JPanel getjPanelSubMenu() {
        return jPanelSubMenu;
    }

    public LinkedList<String> getSubMenuList() {
        return subMenuList;
    }

    public LinkedList<JPanel> getjPanelSubMenuItens() {
        return jPanelSubMenuItens;
    }

    public Boolean getSelected() {
        return selected;
    }

    public void setSelected(Boolean selected) {
        this.selected = selected;
    }

    public void selectModule() {
        selected = !selected;
    }
}
